package mspbots.hubspot.data.core.synclogs;

import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * mspbots.cw.data.core.synclogs.AutoCleanupDataLogs
 *
 * @author <a href="https://github.com/vnobo">Alex bob</a>
 * @date Created by 2020/10/12
 */
@Log4j2
@Component
@RequiredArgsConstructor
public class CleanupLogsTimer {

    private final SyncLogsRepository syncLogsRepository;

    @Scheduled(cron = "0 0 9 * * ?")
    public void taskCleanupLogs() {
        this.syncLogsRepository.deleteByTimeBefore(LocalDateTime.now().minusDays(30))
                .subscribe(result -> log.info("Clean up logs data result [{}]", result));
    }
}
